package org.mspring.platform.api.rss.elements;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import electric.xml.Element;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月26日
 */
public abstract class DublinCore implements Serializable {
    private static final long serialVersionUID = -3094655768856110652L;

    private String dcTitle;
    private String dcCreator;
    private String dcSubject;
    private String dcDescription;
    private String dcPublisher;
    private String dcContributor;
    private Date dcDate;
    private String dcType;
    private String dcFormat;
    private String dcIdentifier;
    private String dcSource;
    private String dcLanguage;
    private String dcRelation;
    private String dcCoverage;
    private String dcRights;

    public static String dc;
    public static String rdf;

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'kk:mmZZZZ");

    static void init(Element paramElement) {
        Element localElement = paramElement.getDocument().getRoot();
        if (dc == null)
            dc = localElement.getNamespace("dc");
        if (rdf == null)
            rdf = localElement.getNamespace("rdf");
    }

    public String getDcTitle() {
        return this.dcTitle;
    }

    public void setDcTitle(String paramString) {
        this.dcTitle = paramString;
    }

    public String getDcCreator() {
        return this.dcCreator;
    }

    public void setDcCreator(String paramString) {
        this.dcCreator = paramString;
    }

    public String getDcSubject() {
        return this.dcSubject;
    }

    public void setDcSubject(String paramString) {
        this.dcSubject = paramString;
    }

    public String getDcDescription() {
        return this.dcDescription;
    }

    public void setDcDescription(String paramString) {
        this.dcDescription = paramString;
    }

    public String getManagingEditor() {
        return getDcPublisher();
    }

    public String getDcPublisher() {
        return this.dcPublisher;
    }

    public void setManagingEditor(String paramString) {
        setDcPublisher(paramString);
    }

    public void setDcPublisher(String paramString) {
        this.dcPublisher = paramString;
    }

    public String getDcContributor() {
        return this.dcContributor;
    }

    public void setDcContributor(String paramString) {
        this.dcContributor = paramString;
    }

    public Date getDcDate() {
        return this.dcDate;
    }

    public String getDcDateAsString() {
        return sdf.format(this.dcDate);
    }

    public void setDcDate(Date paramDate) {
        this.dcDate = paramDate;
    }

    public void setDcDate(String paramString) throws ParseException {
        this.dcDate = sdf.parse(paramString);
    }

    public String getDcType() {
        return this.dcType;
    }

    public void setDcType(String paramString) {
        this.dcType = paramString;
    }

    public String getDcFormat() {
        return this.dcFormat;
    }

    public void setDcFormat(String paramString) {
        this.dcFormat = paramString;
    }

    public String getDcIdentifier() {
        return this.dcIdentifier;
    }

    public void setDcIdentifier(String paramString) {
        this.dcIdentifier = paramString;
    }

    public String getDcSource() {
        return this.dcSource;
    }

    public void setDcSource(String paramString) {
        this.dcSource = paramString;
    }

    public String getLanguage() {
        return getDcLanguage();
    }

    public String getDcLanguage() {
        return this.dcLanguage;
    }

    public void setLanguage(String paramString) {
        setDcLanguage(paramString);
    }

    public void setDcLanguage(String paramString) {
        this.dcLanguage = paramString;
    }

    public String getDcRelation() {
        return this.dcRelation;
    }

    public void setDcRelation(String paramString) {
        this.dcRelation = paramString;
    }

    public String getDcCoverage() {
        return this.dcCoverage;
    }

    public void setDcCoverage(String paramString) {
        this.dcCoverage = paramString;
    }

    public String getDcRights() {
        return this.dcRights;
    }

    public void setCopyright(String paramString) {
        setDcRights(paramString);
    }

    public String getCopyright() {
        return getDcRights();
    }

    public void setDcRights(String paramString) {
        this.dcRights = paramString;
    }

    protected static void setDublinCoreElements(Element paramElement, DublinCore paramDublinCore) {
        paramDublinCore.setDcTitle(getNSAttrValue(paramElement, rdf, "title"));
        paramDublinCore.setDcContributor(getNSElementValue(paramElement, dc, "contributor"));
        paramDublinCore.setDcCoverage(getNSElementValue(paramElement, dc, "coverage"));
        paramDublinCore.setDcCreator(getNSElementValue(paramElement, dc, "creator"));
        try {
            String str = getNSElementValue(paramElement, dc, "date");
            if (str != null)
                paramDublinCore.setDcDate(str);
        } catch (ParseException localParseException) {
        }
        paramDublinCore.setDcDescription(getNSElementValue(paramElement, dc, "description"));
        paramDublinCore.setDcFormat(getNSElementValue(paramElement, dc, "format"));
        paramDublinCore.setDcIdentifier(getNSElementValue(paramElement, dc, "identifier"));
        paramDublinCore.setDcLanguage(getNSElementValue(paramElement, dc, "language"));
        paramDublinCore.setDcPublisher(getNSElementValue(paramElement, dc, "publisher"));
        paramDublinCore.setDcRelation(getNSElementValue(paramElement, dc, "relation"));
        paramDublinCore.setDcRights(getNSElementValue(paramElement, dc, "rights"));
        paramDublinCore.setDcSource(getNSElementValue(paramElement, dc, "source"));
        paramDublinCore.setDcSubject(getNSElementValue(paramElement, dc, "subject"));
        paramDublinCore.setDcTitle(getNSElementValue(paramElement, dc, "title"));
        paramDublinCore.setDcType(getNSElementValue(paramElement, dc, "type"));
        paramDublinCore.setDcType(getNSElementValue(paramElement, dc, "generator"));
    }

    protected static String getNSAttrValue(Element paramElement, String paramString1, String paramString2) {
        return paramElement.getAttributeValue(rdf, paramString2);
    }

    protected static String getElementValue(Element paramElement, String paramString) {
        String str = null;
        Element localElement = paramElement.getElement(paramString);
        if (localElement != null)
            str = localElement.getTextString();
        return str;
    }

    protected static String getNSElementValue(Element paramElement, String paramString1, String paramString2) {
        String str = null;
        Element localElement = paramElement.getElement(paramString1, paramString2);
        if (localElement != null)
            str = localElement.getTextString();
        return str;
    }
}